/**
 *
 */
package com.biotecan.genome.cytobandviewer.data;

import java.util.Collection;
import java.util.List;

/**
 * @author SuFeng
 * chromosome collection
 */
public class Chromosomes {

    //collection of chromosome
    private Collection<Chromosome> list;
    //the max length of chromosome in  collection
    private long maxLength = Long.MIN_VALUE;

    public long getMaxLength() {
        return maxLength;
    }

    private void setMaxLength() {
        if (!list.isEmpty()) {
            for(Chromosome chr : list){
                List<Cytoband> bands = chr.getBands();
                long min=Long.MAX_VALUE;
                long max=Long.MIN_VALUE;
                for(Cytoband cytoband : bands){
                    
                    if(cytoband.getStart()<min){
                        min = cytoband.getStart();
                    }
                    
                    if(cytoband.getEnd()>max){
                        max = cytoband.getEnd();
                    }
                    
                }//bands
                chr.setStart(min);
                chr.setEnd(max);
                chr.setLength(max-min);
                if(max>maxLength){
                    maxLength = max;
                }
                
            }//list
        }
    }

    public Chromosomes(Collection<Chromosome> collection) {
        this.list = collection;
        this.setMaxLength();
    }

    /**
     * @return the list
     */
    public Collection<Chromosome> getList() {
        return list;
    }

    /**
     * @param list the list to set
     */
    public void setList(Collection<Chromosome> list) {
        this.list = list;
    }
}
